package controllers

import (
	"github.com/goravel/framework/contracts/http"
	"github.com/goravel/framework/facades"
	httpfacades "github.com/hulutech-web/http_result"
	"goravel/app/models"
)

type DashboardController struct {
	//Dependent services
}

func NewDashboardController() *DashboardController {
	return &DashboardController{
		//Inject services
	}
}

func (r *DashboardController) Index(ctx http.Context) http.Response {
	//运营商数量
	var admins_count int64
	facades.Orm().Query().Model(&models.User{}).Where("is_admin=?", 2).Count(&admins_count)
	//总用户数
	var users_count int64
	facades.Orm().Query().Model(&models.User{}).Count(&users_count)
	//设备数量
	var devices_count int64
	facades.Orm().Query().Model(&models.Device{}).Count(&devices_count)

	//指令数据
	var readCmds_count int64
	facades.Orm().Query().Model(&models.Readcmd{}).Count(&readCmds_count)

	//设备总数据
	var businessdatas_count int64
	facades.Orm().Query().Model(&models.Businessdata{}).Count(&businessdatas_count)

	//位置信息数据
	var historytracks_count int64
	facades.Orm().Query().Model(&models.Historytrack{}).Count(&historytracks_count)

	return httpfacades.NewResult(ctx).Success("", http.Json{
		"admins_count": admins_count,
		"users_count":  users_count,

		"devices_count": devices_count,

		"readCmds_count": readCmds_count,

		"businessdatas_count": businessdatas_count,

		"historytracks_count": historytracks_count,
	})
}
